/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package translator;

import java.util.HashMap;

/**
 *
 * @author Luuk
 */
public class Translator {
    
    private static Translator instance;
    private HashMap<String, String> dutchToEng;
    private HashMap<String, String> engToDutch;
    
    /**
     * Singleton class that creates two hashmaps for translating purposes.
     */
    private Translator(){
        dutchToEng = new HashMap<String, String>();
        dutchToEng.put("de", "the");
        dutchToEng.put("lui", "lazy");
        dutchToEng.put("vos", "fox");
        dutchToEng.put("snel", "quick");
        dutchToEng.put("springt", "jumps");
        dutchToEng.put("over", "over");
        dutchToEng.put("hond", "dog");
        dutchToEng.put("bruin", "brown");
        dutchToEng.put("stoel", "chair");
        dutchToEng.put("toetsenbord", "keyboard");
        
        engToDutch = new HashMap<String, String>();
        engToDutch.put("the", "de");
        engToDutch.put("lazy", "lui");
        engToDutch.put("fox", "vos");
        engToDutch.put("quick", "snel");
        engToDutch.put("jumps", "springt");
        engToDutch.put("over", "over");
        engToDutch.put("dog", "hond");
        engToDutch.put("brown", "bruin");
        engToDutch.put("chair", "stoel");
        engToDutch.put("keyboard", "toetsenbord");
    }
    
    /**
     * Static constructor for singleton purposes.
     * @return available Translator object or a newly created one.
     */
    public static Translator getTranslator(){
        if(instance == null){
            instance = new Translator();
        }
        return instance;
    }
    
    /**
     * Translate a word from Dutch to English
     * @param word, the word that needs to be translated.
     * @return translated word or word between brackets if translation is impossible.
     */
    public String translateDutchToEng(String word){
        if(dutchToEng.containsKey(word)){
            return dutchToEng.get(word);
        } else {
            return "[" + word + "]";
        }
    }
    /**
     * Translate a word from English to Dutch
     * @param word, the word that needs to be translated.
     * @return translated word or word between brackets if translation is impossible.
     */
    public String translateEngToDutch(String word){
        if(engToDutch.containsKey(word)){
            return engToDutch.get(word);
        } else {
            return "[" + word + "]";
        }
    }
}
